/**
 * 
 */
package instant.mail;

import android.util.Log;

/**
 * @author qiangli
 *
 */
public class Stopwatch {
	private static String TAG = "*****Stopwatch*****";

	private static long begin;
	private static long start;
	private static long stop;
	private static long end;
	
	private static int mark = Integer.MAX_VALUE;
	private static Object startTag = null;
	
	private Stopwatch() {
	}
	
	public static void begin(int m) {
		mark = m;
		begin = System.currentTimeMillis();
		start = System.currentTimeMillis();
		stop = System.currentTimeMillis();
		end = System.currentTimeMillis();
		Log.d(TAG + " >>BEGIN:", "begin: " + begin );
	}
	
	public static void start(Object tag) {
		startTag = tag;
		start = System.currentTimeMillis();
		Log.d(TAG + " ==>>START:"+ tag,  "since: " + (start - begin) + " start: " + start +" begin: " + begin);
	}
	
	public static void stop(Object tag) {
		stop = System.currentTimeMillis();
		long elapsed = (stop - start);
		String ms = (elapsed > mark ? " ######## " : "");
		Log.d(TAG + " ==<<STOP:"+ tag, "elapsed: " + ms + elapsed + ms +" since: " + (start - begin) + " start: " + start +" stop: " + stop +" begin: " + begin);
	}
	
	public static void restart(Object tag) {
		stop(startTag);
		start(tag);
	}

	public static void end() {
		end = System.currentTimeMillis();
		Log.d(TAG + " <<END:", "taken: " + (end - begin)+ " begin: " + begin +" end: "+ end);
	}
}
